package com.ruoyi.ihome.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ihome.domain.IhTopicTag;
import com.ruoyi.ihome.service.IIhTopicTagService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帖子标签管理Controller
 * 
 * @author ruoyi
 * @date 2024-08-16
 */
@RestController
@RequestMapping("/ihome/topicTag")
public class IhTopicTagController extends BaseController
{
    @Autowired
    private IIhTopicTagService ihTopicTagService;

    /**
     * 查询帖子标签管理列表
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicTag:list')")
    @GetMapping("/list")
    public TableDataInfo list(IhTopicTag ihTopicTag)
    {
        startPage();
        List<IhTopicTag> list = ihTopicTagService.selectIhTopicTagList(ihTopicTag);
        return getDataTable(list);
    }

    /**
     * 导出帖子标签管理列表
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicTag:export')")
    @Log(title = "帖子标签管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IhTopicTag ihTopicTag)
    {
        List<IhTopicTag> list = ihTopicTagService.selectIhTopicTagList(ihTopicTag);
        ExcelUtil<IhTopicTag> util = new ExcelUtil<IhTopicTag>(IhTopicTag.class);
        util.exportExcel(response, list, "帖子标签管理数据");
    }
    @PostMapping("/inserttopicandtag")
    public AjaxResult insertTopicAndTag(Long tagId, Long topicId) {
        int res = ihTopicTagService.insertTopicAndTag(tagId, topicId);
        return AjaxResult.success(res);
    }
    /**
     * 获取帖子标签管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicTag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ihTopicTagService.selectIhTopicTagById(id));
    }

    /**
     * 新增帖子标签管理
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicTag:add')")
    @Log(title = "帖子标签管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IhTopicTag ihTopicTag)
    {
        return toAjax(ihTopicTagService.insertIhTopicTag(ihTopicTag));
    }

    /**
     * 修改帖子标签管理
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicTag:edit')")
    @Log(title = "帖子标签管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IhTopicTag ihTopicTag)
    {
        return toAjax(ihTopicTagService.updateIhTopicTag(ihTopicTag));
    }

    /**
     * 删除帖子标签管理
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicTag:remove')")
    @Log(title = "帖子标签管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ihTopicTagService.deleteIhTopicTagByIds(ids));
    }
}
